﻿namespace _151反转字符串中的单词
{
    internal class Program
    {
        static void Main(string[] args)
        {
            string s = "  hello world  ";
            Console.WriteLine(Solution.ReverseWords(s));

        }
    }
    public class Solution
    {
        /// <summary>
        /// API 解法
        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>
        public static string ReverseWords(string s)
        {
            string[] words = s.Split(' ', StringSplitOptions.RemoveEmptyEntries);
            Array.Reverse(words);
            return string.Join(" ", words);
        }
        public static string ReverseWords2(string s)
        {
            //去掉字符串开头的空白字符
            int left = 0;
            int right = s.Length - 1;
            while (left < right && s[left]==' ') 
            { 
                left++;
            } 
            //去掉字符串结尾的空白字符
            while (left <= right && s[right] == ' ')
            {
                right--;
            }
        }


    }
}
